<?php
namespace Index\Controller;
use Think\Controller;
/**
 * 前台内容管理控制器
 */
 class ArticleController extends  CommonController{
 	
	public function index(){
		header("Content-type:text/html;charset=utf-8");
//		
//		$str = '<lable:index_test>';
//
//// $reg = "#<b[^>]*>(.*?)<\/b>#";
//	$reg = "/>(.*?)<\/b>/";
// preg_match_all($reg , $str , $matches);
// var_dump($matches);
//		
//		
//		
//		die;

		$aid = I('get.aid','0'); 						 					//文章id
		$cid = I('get.cid','0');						 					//栏目id		
		$categoryData = M('category')->where("cid='{$cid}'")->find();		//通过cid 查询栏目模型
		$mid = $categoryData['duosute_model_mid'];
		$modelName = M("Model")->where("mid='{$mid}'")->find();
		$defaultTable = $modelName['mdefault_field'];						//默认表明
		$aloneTable = $modelName['mmodel_name'];							//独立表
		//关联表查询数据   //组合查询语句
		$join = ' join duosute_'. $aloneTable . ' on duosute_' .$defaultTable.'.id= duosute_'.$aloneTable.'.aid'; 
		$articleData = M($defaultTable)->JOIN($join)->where("aid = '{$aid}'")->find(); //查询内容

		//查询默认表内容
		$articleData = M($defaultTable)->where("id = '{$aid}'")->find(); 
		$selfData =  M($aloneTable)->where("aid = '{$aid}'")->find(); 
		if($selfData){
			foreach($selfData as $k => $v){
				$articleData[$k] = $v;
			}
		}
		echo '<hr />';
		p($articleData);
		echo '<hr />';
		
//				//时间重组
//			$articleData['aauthor'] = 'qianbaidu';//为做查询 赋默认值
			$articleData['aaddtime'] = date('Y-m-d H:i:s',$articleData['aaddtime']);
	
		p($articleData);
		$this->assign('articleData',$articleData);
		$this->display('article_article');
	}
 }
